import { defineConfig, loadEnv } from 'vite';
import { proxyJson, vitePlugins } from '@iboot-vite/vue-plugins';
import vueJsx from '@vitejs/plugin-vue-jsx';
import path, { join } from 'path';
import { theme } from 'ant-design-vue';
import convertLegacyToken from 'ant-design-vue/lib/theme/convertLegacyToken';
const mapToken = theme.defaultAlgorithm(theme.defaultSeed);
const v3Token = convertLegacyToken.default(mapToken);
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  return {
    server: {
      port: Number(env.VITE_APP_PORT),
      host: Boolean(env.VITE_APP_HOST),
      proxy: {
        "/mock/typicode": {
          target: "http://jsonplaceholder.typicode.com",
          changeOrigin: true,
          rewrite: (path) => path.replace('/mock/typicode', '')
        }
      }
    },
    base: env.VITE_APP_BASE,
    resolve: {
      alias: {
        '@': join(__dirname, 'src')
      }
    },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: v3Token
        }
      }
    },
    plugins: [
      ...vitePlugins({
        svgIcon: {
          iconDirs: [path.resolve(process.cwd(), env.VITE_APP_SVG_PATH)],
          symbolId: env.VITE_APP_SVG_NAME
        },
        inject: {
          $api: path.resolve(__dirname, 'src/api.ts')
        }
      }),
      vueJsx()
    ]
  };
});
